library app_base_page;

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

abstract class BasePage<T extends StatefulWidget> extends BaseState<T> {

  @override
  initChild(BuildContext c) =>
      Scaffold(
        key: initKey(),
        body: initPageBody(c),
        appBar: initAppbar(),
        drawer: initDrawer(),
        endDrawer: initEndDrawer(),
        drawerEdgeDragWidth: initDrawerEdgeDragWidth(),
        bottomNavigationBar: initBottomNavigationBar(),
        floatingActionButton: initFloatingActionButton(),
        floatingActionButtonAnimator: initFloatingActionButtonAnimator(),
        floatingActionButtonLocation: initFloatingActionButtonLocation(),
      );

  GlobalKey<ScaffoldState> initKey() => null;

  bool pageV() => true;

  Widget initPageBody(BuildContext c);

  PreferredSizeWidget initAppbar() => null;

  Widget initDrawer() => null;

  Widget initEndDrawer() => null;

  double initDrawerEdgeDragWidth() => 20;

  Widget initBottomNavigationBar() => null;

  Widget initFloatingActionButton() => null;

  FloatingActionButtonAnimator initFloatingActionButtonAnimator() => null;

  FloatingActionButtonLocation initFloatingActionButtonLocation() => null;
}

abstract class BaseState<T extends StatefulWidget> extends State<T> {
  @override
  void initState() {
    super.initState();
    SystemChrome.setPreferredOrientations(pageV()
        ? [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]
        : [DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight]);
  }

  @override
  build(BuildContext c) => initChild(c);

  bool pageV() => true;

  Widget initChild(BuildContext c);
}
